Out: Monday, November 7, 2016
Due: Monday, November 14, 2016 at 600pm local time.
The goal of this problem set is to help you design simple class systems and methods on them.
Here's an example:
#lang racket (require rackunit) (require "extras.rkt") (require 2htdp/universe) (require 2htdp/image)You may require "sets.rkt" if you need it. You may not require any other libraries.
Problem:
Your boss at NextPython, Inc. spent the weekend at a wild party in the Valley, where he spent too much time taking drugs and listening to American folk music from the 1960's. He has come out of his hangover just long enough to pull you off your GarterSnake project and tell you to to build a marvelous toy, called the MetaToy. The MetaToy will consist of a canvas on which the child will paint and interact with a variety of toys.
There are many unspecified parameters in the description above. Choose parameters (like speed, the exact way in which items grow and shrink, etc.) so that the result is visually satisfying.
I believe this problem is easier than the last one, so have some fun with it.
It is acceptable (and even encouraged) to reuse code from the Example files.
Here's a demo.
Your solution should be a file named q1.rkt and should provide the following interfaces and functions:
make-metatoy : ListOfToys -> Metatoy RETURNS: a Metatoy with the given list of toys. NOTE: The Metatoy<%> interface extends the World<%> interface, so the result of make-metatoy is something that big-bang can use as a world. run : PosNum -> Metatoy GIVEN: a frame rate (in seconds/tick) EFFECT: creates a MetaToy with no toys in it, and runs it using big-bang at the given frame rate. Returns the final state of the Metatoy. make-throbber: PosInt PosInt -> Toy GIVEN: an x and a y position RETURNS: an object representing a throbber at the given position. make-clock : PosInt PosInt -> Toy GIVEN: an x and a y position RETURNS: an object representing a clock at the given position. make-politician : PosInt PosInt -> Toy GIVEN: an x and a y position RETURNS: an object representing a politician at the given position. Interfaces: ;; A Metatoy is an object of any class that implements Metatoy<%>. ;; (You will only need one such class) (define Metatoy<%> (interface ;; the (World<%>) says that Metatoy<%> inherits from World<%> ;; This means that any class that implements Metatoy<%> must ;; implement all the methods from World<%> plus all the methods ;; defined here. In this case, there is just one additional method, ;; called get-toys. (World<%>) ;; -> ListOfToy get-toys )) ;; A Toy is an object of any class that implements Toy<%> ;; You will probably have three such classes, one for each kind of toy. (define Toy<%> (interface ;; The interface Toy<%> inherits from the interface Widget<%>. ;; This means that any class that implements Toy<%> must implement ;; all the methods from Widget<%> plus all the methods defined here. (Widget<%>) ;; Note: the Widgets of the space-invader-examples don't respond ;; to mouse "move" events, but some of our toys do. So we add an ;; after-move method to the interface. ;; Int Int -> Toy ;; RETURNS: the state of this toy that should follow a mouse-move ;; at the given coordinates after-move ;; -> Int ;; RETURNS: the x or y position of the center of the toy toy-x toy-y ;; -> Int ;; RETURNS: some data related to the toy. The interpretation of ;; this data depends on the class of the toy. ;; for a throbber, it is the current radius of the throbber ;; for the clock, it is the current value of the clock ;; for a politician, it is the current distance to the mouse toy-data ))
When you do this problem, remember the principle of Iterative Development: get something simple working, and then add features as necessary.
Effective with this problem, you may turn in your solution as a set of files; our scripts will collect all of the files in your set09 directory. Just make sure that your q1.rkt provides all the required functions. If you do split your solution across several files, we recommend that you have a file named interfaces.rkt that provides all of your interfaces and then one file for each class you define.
Last modified: Wed Nov 9 13:35:22 Eastern Standard Time 2016